#include "PrecompiledHeader.h"
#include "ICtrlTextSupport.h"

/*--------------------------------------------------------------------------*/

ICtrlTextSupport::ICtrlTextSupport()
{
	this->m_font = NULL;
	this->m_fontColor = Color::Pink;
	this->m_fontName = "default";
}

/*--------------------------------------------------------------------------*/

ICtrlTextSupport::~ICtrlTextSupport()
{

}

/*--------------------------------------------------------------------------*/

Font* ICtrlTextSupport::GetFont()
{
	if (this->m_font == NULL)
	{
		g_Resources->Get(this->m_fontName, &this->m_font);
	}

	return this->m_font;
}

/*--------------------------------------------------------------------------*/

void ICtrlTextSupport::SetFont(Font* font)
{
	this->m_font = font;
}

/*--------------------------------------------------------------------------*/

void ICtrlTextSupport::SetFonteByName(const std::string& name)
{
	this->m_fontName = name;
	this->m_font = NULL;
}

/*--------------------------------------------------------------------------*/

void ICtrlTextSupport::ReadTextSupport(std::ifstream& file, const std::string& firstWord)
{
	if (firstWord == "font")
	{
		std::string fontname;
		file >> fontname;

		this->SetFonteByName(fontname);
	}
	else if (firstWord == "label")
	{
		std::string str;
		char tmp = '\0';

		while ((tmp = file.get()) != '\n')
		{
			str += tmp;
		}

		this->m_label = str;
	}
	else if (firstWord == "fontcolor")
	{
		uint r, g, b, a;
		file >> r >> g >> b >> a;

		this->m_fontColor = Color(r, g, b, a);
	}
}

/*--------------------------------------------------------------------------*/

const std::string& ICtrlTextSupport::GetLabel() const
{
	return this->m_label;
}

/*--------------------------------------------------------------------------*/

void ICtrlTextSupport::SetLabel(const std::string& label)
{
	this->m_label = label;
}

/*--------------------------------------------------------------------------*/